<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>js简单应用</title>
  <style>
    
   *{
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
   }
    .form{
      background-color: skyblue;
      height: 300px;
      width: 500px;
      margin: 0 300px;
    }
    .text{
      margin-left: 20px;
    }
    .login,.reset{
      height: 30px;
      width: 50px;
      margin-left: 30px;
      padding:5px;
    }

  </style>
</head>

<body>
  <script>
    function check() {
      let un = document.getElementById("username").value;
      let p = document.getElementById("password").value;
      if (un.length < 5 || un.length > 14) {
        alert("用户名应在5-14位之间!");
        document.getElementById('username').focus();
        return false;
      }

      if (p.length > 12) {
        alert("密码应在0-12位之间!");
        document.getElementById('password').focus();
        return false;
      }

      return true;
    }
    
  </script>
  <div class="form">


    <form onsubmit="return check()" action="#">
      <p class="text">用户名:&emsp;<input type="text" value="王 其" id="username" placeholder="请输入用户名"></p>
      <br>
      <p class="text">密&emsp;码:&emsp;<input type="password" name="" id="password" placeholder="请输入6位密码"></p>

      <br>
      <div>

        <input type="submit" class="login" value="登录">
         <input type="reset" class="reset"  value="重置">
      </div>
    </form>
  </div>
</body>

</html>